package com.link.base.base.fund.controller;


import com.link.base.base.fund.model.BillAccountDetail;
import com.link.base.base.fund.service.BillAccountDetailService;
import com.link.core.cllog.LCLogger;
import com.link.core.basic.controller.BasicController;
import com.link.core.basic.service.BasicService;
import com.link.core.basic.service.BasicServiceException;
import com.link.core.basic.service.ServiceException;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.util.HashMap;
import java.util.Map;


/**
 * Copyright  hande Company. All Rights Reserved.
 * 财务管理
 * 对账单列表
 * 对账单明细
 * @author  crm4
 * @date:   2018-06-26
 * @version 1.0
 */

@Controller
@RequestMapping("/link/billAccountDetail")
public class BillAccountDetailController extends BasicController<BillAccountDetail> {


    @Resource
    private BillAccountDetailService billAccountDetailService;

    @Override
    public BasicService<BillAccountDetail> getBasicService() throws Exception {
        return billAccountDetailService;
    }

    /**
     * 将对账单数据存储为PDF
     * @author guoshan
     * @date 2019/03/19
     */
    @RequestMapping(value = "/printBillAccntDetail")
    @ResponseBody
    public Map<String, Object> printBillAccntDetail(BillAccountDetail entity, HttpSession session,
                                                  HttpServletRequest request, HttpServletResponse response) {
        Map<String, Object> result = new HashMap<String, Object>(4);
        try {
            if (null == entity.getHeadId()) {
                throw new ServiceException("PUBLIC-018");
            }
            String  pdfUrl = billAccountDetailService.printBillPdf(entity);
            result.put("pdfUrl",pdfUrl);
            result.put("success", true);
        } catch (BasicServiceException e) {
            LCLogger.withException(e);
            result.put("success", false);
            result.put("result", e.getMessage());
            result.put("detailMessage", e.getDetailMessage());
        } catch (Exception e) {
            LCLogger.withException(e);
            result.put("success", false);
            result.put("result", "打印PDF发生错误");
        }
        return result;
    }
}
